package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:继承和多态
 * User: LianBao
 * Date: 2024-03-03
 * Time: 14:12
 */

class Animal {
    public String name;
    int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Animal() {

    }

    public Animal eat() {
        System.out.println(this.name + "吃饭");
        return null;
    }
}

class Bird extends Animal {

    public Bird(String name, int age) {
        super(name, age);
    }

    public Bird() {

    }

    public void gugu() {
        System.out.println(this.name + "咕咕咕");
    }

    @Override
    public Bird eat() {
        System.out.println(this.name + "吃鸟粮");
        return null;
    }
}

class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }

    public Dog() {

    }

    @Override
    public Dog eat() {
        System.out.println(this.name + "吃狗粮");
        return null;
    }

    public void bark() {
        System.out.println(this.name + "汪汪汪");
    }
}

public class Test {
    public static void func(Animal animal) {
        animal.eat();
    }

    public static void main(String[] args) {
        Animal animal = new Animal();
        Dog dog = new Dog();
        Bird bird = new Bird();

        animal = dog;
//        animal = bird;
        if (animal instanceof Bird) {
            bird = (Bird) animal;
        } else {
            System.out.println("animal instanceof Bird not!");
        }

    }

    public static void main1(String[] args) {
//        Animal animal = new Dog("小黑", 10);
//        animal.eat();
//        animal.bark();
        func(new Dog("小黑", 10));
        func(new Bird("小鸟", 9));
    }
}
